/*
 * Helper.h
 *
 *  Created on: Apr 17, 2017
 *      Author: zhangjf
 */

#ifndef SRC_GLOBAL_HELPER_H_
#define SRC_GLOBAL_HELPER_H_

#include <Poco/Logger.h>
#include <Poco/File.h>
#include <string>
#include <sstream>

using namespace std;
using namespace Poco;

namespace std
{

template <typename T>
std::string to_string( const T& n )
{
	std::ostringstream stm ;
	stm << n ;
	return stm.str() ;
}

}

namespace util
{

class Helper
{
public:
	static void initLogger(Logger& pLog, std::string& logFile);
	static void initLogger(Logger& pLog);
	static bool readFileFromZip(const string& zipFile, string& subFile, string& outStr);
	static std::string joinStrings(std::vector<std::string>& vecString, std::string& strSep);
	static void escapeJsonString(std::string& str);
};

std::string str2hex(std::string& str);
void replaceSubString(std::string& s, std::string const & t, std::string const & w);

inline string& ltrim(string &str, const string& trimChars = " \t\n\r") {
    str.erase(0, str.find_first_not_of(trimChars));
    return str;
}

inline string& rtrim(string &str, const string& trimChars = " \t\n\r") {
    str.erase(str.find_last_not_of(trimChars) + 1);
    return str;
}

inline string& trim(string &str, const string& trimChars = " \t\n\r") {
    ltrim(rtrim(str, trimChars), trimChars);
    return str;
}


} /* namespace global */

#endif /* SRC_GLOBAL_HELPER_H_ */
